package com.pzhuweb.sgblog.controller;

import com.pzhuweb.sgblog.domain.dto.RoleDto;
import com.pzhuweb.sgblog.domain.dto.RoleStatusDto;
import com.pzhuweb.sgblog.domain.utils.ResponseResult;
import com.pzhuweb.sgblog.service.SystemRoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 鄧浩奇
 * @classname SystemRoleController
 * @description
 * @since 2023/8/21 16:52
 **/

@RestController
@RequestMapping("/system/role")
public class SystemRoleController {

    @Resource
    private SystemRoleService systemRoleService;

    /*
     * 查询角色列表
     * */
    @GetMapping("listAllRole")
    public ResponseResult<?> listAllRole() {
        return systemRoleService.listAllRole();
    }

    /*
     * 角色分页
     * */
    @GetMapping("/list")
    public ResponseResult<?> list(Integer pageNum, Integer pageSize, String roleName, String status) {
        return systemRoleService.getRolePage(pageNum, pageSize, roleName, status);
    }

    @PutMapping("/changeStatus")
    public ResponseResult<?> changeStatus(@RequestBody RoleStatusDto statusDto) {
        return systemRoleService.changeStatus(statusDto);
    }

    @PostMapping()
    public ResponseResult<?> insertRole(@RequestBody RoleDto roleDto) {
        return systemRoleService.insertRole(roleDto);
    }

    @GetMapping("/{id}")
    public ResponseResult<?> getRoleInfo(@PathVariable("id") Long id) {
        return systemRoleService.getRoleInfo(id);
    }

    /*
    * 修改角色
    * */
    @PutMapping()
    public ResponseResult<?> updateRole(@RequestBody RoleDto roleDto) {
        return systemRoleService.updateRole(roleDto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult<?> deleteRoleById(@PathVariable("id") List<Long> roleIds) {
        return systemRoleService.deleteRoleById(roleIds);
    }

}
